<template>
	<view class="container">
		<uni-section title="食物图片" sub-title="" type="square">
			<image :src="'http://localhost:8090/foodapp'+data.icon" mode="widthFix"></image>
		</uni-section>
		<uni-section title="食物名称" sub-title="" type="square">
			{{data.name}}
		</uni-section>
		<uni-section title="食物类别" sub-title="" type="square">
			{{data.type}}
		</uni-section>
		<uni-section title="食物价格" sub-title="" type="square">
			￥{{data.price}}元
		</uni-section>
		<uni-section title="食物介绍" sub-title="" type="square">
			{{data.description}}
		</uni-section>
		<uni-section title="菜品评论" sub-title="" type="square">
			<navigator :url="'../comment/commentlist?foodid='+data.id" open-type="navigate"><button type="default">查看评论</button></navigator>
			<navigator url="../comment/addcomment" open-type="navigate"><button type="default">发表评论</button></navigator>
		</uni-section>
		<uni-popup ref="popup" type='dialog'>
			<uni-popup-dialog title="美食发表评论" confirmText="发表" @confirm="postMessage">
				<view style="width: 100%;">
					<view>味道：</view>
					<uni-rate value="0"></uni-rate>
					<view>价格：</view>
					<uni-rate value="0"></uni-rate>
					<view>评论：</view>
					<uni-easyinput type="textarea" v-model="message" placeholder="请输入评论内容" />
				</view>
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				message: "asasdasdd",
				data: {
					"id": 1,
					"name": "烤鸭",
					"type": "肉类",
					"icon": "/images/1.png",
					"description": "烤鸭是北京和南京的一道特色名菜,属于北京菜或金陵菜,该菜品以色泽红艳,肉质细嫩,味道醇厚,肥而不腻的特色,被誉为“天下美味”而驰名中外,其色泽略黄,柔软淡香,夹卷其他荤素食物食用,为宴席常用菜点,更是家常风味美食。",
					"price": 88.5
				},
				
			}
		},
		methods: {

		},
		onLoad(e) {
			let id = e.id
			uni.request({
				url: 'http://localhost:8090/foodapp/food/findone',
				method: 'POST',
				data: {
					id: id
				},
				success: res => {
					this.data = res.data.data
				},
				fail: () => {},
				complete: () => {}
			});
			
		},
		showPostDialog() {
			this.$refs.popup.open()
		},
		postMessage(e) {
			 let data = {
				comment: this.message,
				foodId: this.data.id,
				postDate: new Date().toISOString().substring(0, 10),
				userId: uni.getStorageSync('userInfo').id
			}
			uni.request({
				url: 'http://localhost:8090/foodapp/comments/add',
				method: 'POST',
				data: data,
				success: res => {
					console.log(res);
					if (res.data.success) {
						uni.showToast({
							title: '发表成功'
						});
						this.getCommentListTop5()
					} else {
						uni.showToast({
							title: '发表失败',
							icon: "error"
						});
					}
				},
				fail: () => {
					uni.showToast({
						title: '发表失败',
						icon: "error"
					});
				},
				complete: () => {}
			});
		}
	}
</script>

<style>
	.container {
		padding: 10px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
